/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gridworld_v04;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 *
 * @author Jonah
 */
public class Board extends JPanel{
    /*implementation comment*/
    ////<editor-fold defaultstate="collapsed" desc="Static Variables">
    //</editor-fold>
    ////<editor-fold defaultstate="collapsed" desc="Instanced Variables">
    private int pixels, rows, columns;
    private Tile[] tiles;
    private Game game;
    private GWimages icons;

    public int getColumns() {
        return columns;
    }
    public int getPixels() {
        return pixels;
    }
    public int getRows() {
        return rows;
    }
    public Tile getTile(Integer tileIndex) {
        return tiles[(int)tileIndex];
    }
    //</editor-fold>
    ////<editor-fold defaultstate="collapsed" desc="Constructor">
    public Board(int pixels, int rows, int columns, Game game) {
        this.pixels = pixels;
        this.rows = rows;
        this.columns = columns;
        this.game = game;
        
        icons = new GWimages(pixels);
                
        //swing intializations
        setLayout(new GridLayout(rows, columns));
        setPreferredSize(new Dimension(pixels*columns, pixels*rows));
        
        generateTiles();
    }
    //</editor-fold>
    ////<editor-fold desc="Class Methods">
    private void generateTiles() {
        tiles = new Tile[rows*columns];
        for (int i = 0; i < (rows*columns); i++){
            tiles[i] = new Tile(i, game, this, icons);
            tiles[i].setText(Integer.toString(i));
            add(tiles[i]);
        }
        for(Tile t : tiles){
            t.generateNieghbors(rows, columns);
        }
    }
    //</editor-fold>
    ////<editor-fold defaultstate="collapsed" desc="Interface Override Methods">
    //</editor-fold>

    int getNumberOfTiles() {
        return tiles.length;
    }
}
